package com.jiyun.controller;

import com.jiyun.model.statistics.SignPerformance;
import com.jiyun.result.Result;
import com.jiyun.service.SignPerformanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/signPerformance")
@Api("签约业绩统计")
public class SignPerformanceController {
    @Resource
    private SignPerformanceService signPerformanceService;
   @ApiOperation("签约业绩统计")
    @GetMapping("/statistics/bar")
    public Map<String, Object> statisticsBar(){
        List<SignPerformance> list = signPerformanceService.list();
        //实际签约量的集合
        List<Integer> actualList = new ArrayList<>();
        list.forEach(item -> actualList.add(item.getActualSignCount()));
        //未完成签约量的集合
        List<Integer> targetList = new ArrayList<>();
        list.forEach(item -> targetList.add(item.getTargetSignCount()-item.getActualSignCount()));
        //标题的集合
        ArrayList<String> titleList = new ArrayList<>();
        list.forEach(item -> titleList.add(item.getDate().toString()));
        Map<String, Object> map = new HashMap<>();
        map.put("actualList", actualList);
        map.put("targetList", targetList);
        map.put("titleList", titleList);
        return map;
    }

    @ApiOperation("查询所有签约业绩")
    @GetMapping("/findAllSignPerformance")
    public Result findAllSignPerformance(){
        return Result.ok(signPerformanceService.list());
    }
}
